﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Timers;

namespace BEGDC.Office.Library
{
    public abstract class OfficeSession : IDisposable
    {
        private bool is_closed = false;
        public bool IsClosed
        {
            get
            {
                return is_closed;
            }
        }

        private Timer timer;

        private const int Life_Cycle = 60000;
        public virtual int LifeCycle
        {
            get
            {
                return Life_Cycle;
            }
        }

        public virtual void Dispose()
        {
            if (!is_closed)
                Close();
        }

        public virtual void Open(string fileName)
        {
            //is_closed = false;
            timer = new Timer(LifeCycle);
            timer.AutoReset = false;
            timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            timer.Enabled = true;
        }

        public virtual void Close()
        {
            if (OnClosed != null)
                OnClosed(this, null);
            if (timer != null)
            {
                timer.Enabled = false;
                timer.Close();
            }
            is_closed = true;
        }

        public abstract void Print();

        public abstract void PrintPreview();

        public abstract void SaveToWeb(string strFileName);

        public abstract void Save();

        public event EventHandler OnTimeout;

        public event EventHandler OnClosed;

        private void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            if (OnTimeout != null)
                OnTimeout(this, e);
            Close();
        }

    }
}
